﻿package net.wangit.framework.action;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import net.wangit.context.ActionContext;
import net.wangit.framework.expression.LabelExpression;
import net.wangit.framework.util.InterceptorLoader;
import net.wangit.support.ActionInterceptor;
import net.wangit.util.Checker;
import net.wangit.util.StringUtil;

/**
 * 动作映射
 * @author watson
 *
 */
@SuppressWarnings("serial")
public class ActionMapping implements Serializable {
	private String domain; //域
	private String groupId; //组
	private String unitId; //单元
	private String unitName; //单元名称
	private String id; //ActionID
	private String name; //Action名称
	private String action; //Action执行者
	private String proxy; //Proxy代理
	private List<ActionInterceptor> interceptors; //拦截器
	private String command; //命令行
	private String parameter; //自定义参数
	private boolean tokenEnabled; //启用令牌
	private String script; //执行脚本
	private String datasource; //数据源
	private String validateUnits[]; //验证单元
	private boolean redirect; //是否重定向
	private String successfulForward; //成功转向
	private String failedForward; //失败转向
	private String successfulMessage; //成功消息
	private String failedMessage; //失败消息
	private boolean hasAccessPrivilege; //访问需要授权
	private boolean published; //是否发布
	private boolean supportLog; //是否记录日志

	public ActionMapping() {
	}

	public String getAction() {
		return action;
	}

	protected void setAction(String action) {
		this.action = action;
	}

	public String getDatasource() {
		return datasource;
	}

	protected void setDatasource(String datasource) {
		this.datasource = datasource;
	}

	public String getFailedForward() {
		return failedForward;
	}

	protected void setFailedForward(String failedForward) {
		this.failedForward = failedForward;
	}

	public String getFailedMessage(ActionContext ac) {
		return LabelExpression.resolve(ac, failedMessage);
	}

	protected void setFailedMessage(String failedMessage) {
		this.failedMessage = failedMessage;
	}

	public String getProxy() {
		return proxy;
	}

	protected void setProxy(String proxy) {
		this.proxy = proxy;
	}

	public String getSuccessfulForward() {
		return successfulForward;
	}

	protected void setSuccessfulForward(String successfulForward) {
		this.successfulForward = successfulForward;
	}

	public String getSuccessfulMessage(ActionContext ac) {
		return LabelExpression.resolve(ac, successfulMessage);
	}

	protected void setSuccessfulMessage(String successfulMessage) {
		this.successfulMessage = successfulMessage;
	}

	public Iterator getInterceptors() {
		return InterceptorLoader.getActionInterceptors(domain, interceptors);
	}

	protected void setInterceptors(List<ActionInterceptor> interceptors) {
		this.interceptors = interceptors;
	}

	public String getId() {
		return id;
	}

	protected void setId(String id) {
		this.id = id;
	}

	public String getDomain() {
		return domain;
	}

	protected void setDomain(String domain) {
		this.domain = domain;
	}

	public boolean isRedirect() {
		return redirect;
	}

	protected void setRedirect(boolean redirect) {
		this.redirect = redirect;
	}

	public String getUnitId() {
		return unitId;
	}

	protected void setUnitId(String unitId) {
		this.unitId = unitId;
	}

	public String getCommand() {
		return command;
	}

	protected void setCommand(String command) {
		this.command = command;
	}

	public String getParameter() {
		return parameter;
	}

	protected void setParameter(String parameter) {
		this.parameter = parameter;
	}

	public String[] getValidateUnits() {
		return validateUnits;
	}

	protected void setValidateUnits(String validateUnits) {
		if (!Checker.isEmpty(validateUnits))
			this.validateUnits = StringUtil.split(validateUnits, ",");
	}

	public String getScript() {
		return script;
	}

	protected void setScript(String script) {
		this.script = script;
	}

	public boolean isTokenEnabled() {
		return tokenEnabled;
	}

	protected void setTokenEnabled(boolean tokenEnabled) {
		this.tokenEnabled = tokenEnabled;
	}

	public String getName() {
		return name;
	}

	protected void setName(String name) {
		this.name = name;
	}

	public String getUnitName() {
		return unitName;
	}

	protected void setUnitName(String unitName) {
		this.unitName = unitName;
	}

	public boolean hasAccessPrivilege() {
		return hasAccessPrivilege;
	}

	protected void setHasAccessPrivilege(boolean hasAccessPrivilege) {
		this.hasAccessPrivilege = hasAccessPrivilege;
	}

	public String getGroupId() {
		return groupId;
	}

	protected void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	public boolean isPublished() {
		return published;
	}

	protected void setPublished(boolean published) {
		this.published = published;
	}

	public boolean isSupportLog() {
		return supportLog;
	}

	protected void setSupportLog(boolean supportLog) {
		this.supportLog = supportLog;
	}
}
